c191db
@@ -15,6 +15,10 @@
  */
 package org.wildfly.swarm.topology.openshift.runtime;
 
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.List;
 
 import com.openshift.restclient.IClient;
@@ -42,6 +46,18 @@
public class NamespaceService implements Service<String> {
 
         this.namespace = System.getenv("KUBERNETES_NAMESPACE");
 
+        if (this.namespace == null) {
+            Path namespaceFile = Paths.get("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
+            if (Files.exists(namespaceFile)) {
+                try {
+                    this.namespace = new String(Files.readAllBytes(namespaceFile));
+                } catch (IOException ignored) {
+                    // shouldn't happen, this file is on tmpfs
+                    // but if it happened anyway, we'll try the following options
+                }
+            }
+        }
+
         if (this.namespace == null) {
             this.namespace = System.getenv("OPENSHIFT_BUILD_NAMESPACE");
         }
